package com.aizhixin.lab.course.course.repository;

import java.util.List;

import com.aizhixin.lab.course.course.entity.Course;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface CourseRepository extends JpaRepository<Course, String> {


    public Page<Course> findAllByCreatedByAndNameLikeIgnoreCaseAndDeleteFlagAndIsPublishAndIsArchiveOrderByCreatedDateDesc(Pageable page,@Param(value = "createdBy") Long createdBy, @Param(value = "name") String name, @Param(value = "deleteFlag") Integer deleteFlag, @Param(value = "isPublish") Boolean isPublish, @Param(value = "isArchive") Boolean isArchive);

    public Page<Course> findAllByCreatedByAndDeleteFlagAndIsPublishAndIsArchiveOrderByCreatedDateDesc(Pageable page,@Param(value = "createdBy") Long createdBy, @Param(value = "deleteFlag") Integer deleteFlag, @Param(value = "isPublish") Boolean isPublish, @Param(value = "isArchive") Boolean isArchive); 

    Page<Course> findByTypeAndCreatedByAndDeleteFlag(Pageable pageable, Integer type, Long createdBy, Integer deleteFlag);

    Page<Course> findByIsPublishAndIsArchiveAndTypeAndCreatedByAndDeleteFlag(Pageable pageable, Boolean isPublish, Boolean isArchive, Integer type, Long createdBy, Integer deleteFlag);

    Page<Course> findByTypeAndCreatedByAndDeleteFlagAndNameLikeIgnoreCase(Pageable pageable, Integer type, Long createdBy, Integer deleteFlag, String name);

    Page<Course> findByIsPublishAndIsArchiveAndTypeAndCreatedByAndDeleteFlagAndNameLikeIgnoreCase(Pageable pageable, Boolean isPublish, Boolean isArchive, Integer type, Long createdBy, Integer deleteFlag, String name);

    Page<Course> findByCreatedByAndDeleteFlagAndNameLikeIgnoreCase(Pageable pageable, Long createdBy, Integer deleteFlag, String name);

    Page<Course> findByIsPublishAndIsArchiveAndCreatedByAndDeleteFlagAndNameLikeIgnoreCase(Pageable pageable, Boolean isPublish, Boolean isArchive, Long createdBy, Integer deleteFlag, String name);

    Page<Course> findByCreatedByAndDeleteFlag(Pageable pageable, Long createdBy, Integer deleteFlag);

    Page<Course> findByIsPublishAndIsArchiveAndCreatedByAndDeleteFlag(Pageable pageable, Boolean isPublish, Boolean isArchive, Long createdBy, Integer deleteFlag);

    Course findByIdAndDeleteFlag(String id, Integer deleteFlag);
    Course findByIdAndIsPublishAndIsArchiveAndDeleteFlag(String id,Boolean isPublish, Boolean isArchive, Integer deleteFlag);
    List<Course> findByIsPublishAndIsArchiveAndCreatedByAndDeleteFlagOrderByCreatedDateDesc(Boolean isPublish, Boolean isArchive, Long createdBy, Integer deleteFlag);
    Long countByCreatedByAndIsPublishAndDeleteFlag(Long createdBy,Boolean isPublish,Integer deleteFlag);
    List<Course> findByTemplateIdAndCreatedByAndDeleteFlag(Long templateId,Long createdBy,Integer deleteFlag);
    List<Course> findByParentIdAndDeleteFlag(String parentId,Integer deleteFlag);
    Long countByCreatedByAndDeleteFlag(Long createdBy,Integer deleteFlag);
    
    Long countByTemplateIdAndDeleteFlag(Long templateId,Integer deleteFlag);
    Long countByTemplateIdAndDeleteFlagAndCreatedBy(Long templateId,Integer deleteFlag,Long createdBy);

    List<Course> findAllByCreatedByAndIsPublishAndDeleteFlagAndIsArchive(Long createdBy,Boolean isPublish, Integer deleteFlag,Boolean isArchive);
    
    List<Course> findAllByCreatedByAndTemplateIdAndIsPublishAndDeleteFlagAndIsArchive(Long createdBy,Long templateId,Boolean isPublish, Integer deleteFlag,Boolean isArchive);

    List<Course> findByDeleteFlag(Integer deleteFlag);

    Course findCourseById(String id);

    List<Course> findByCreatedByAndDeleteFlag(Long createdBy,Integer deleteFlag);

}
